package cn.itcast.gz.ss01.action;

import com.opensymphony.xwork2.ActionSupport;

import cn.itcast.gz.ss01.model.User;

public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private User user;

	public String execute() {
		user = getUser();
		System.out.println(user.getName());
		if (checkUser(user)) {
			return SUCCESS;
		} else {
			return LOGIN;
		}
	}

	private boolean checkUser(User logginUser) {
		if (logginUser.getName().equals(logginUser.getPassword())) {
			return true;
		} else {
			return false;
		}
	}

	public void validate() {
		if (getUser().getName().length() == 0) {
			addFieldError("user.name", "用户名必须输入");
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
